import {
  isLogin
} from '../../utils/isLogin'

Page({
  data: {
    notifyList: []
  },
  onLoad(options) {
    this.getNotifyList()
  },
  getNotifyList() {
    wx.showLoading({
      title: '加载中...',
    })
    wx.request({
      url: 'https://live-api.itheima.net/announcement',
      method: 'GET',
      success: (res) => {
        console.log(res)
        if (res.data.code !== 10000) {
          wx.showToast({
            title: res.data.message,
          })
          return
        }
        this.setData({
          notifyList: res.data.data
        })
      },
      fail: (res) => {
        console.log(res)
        wx.showToast({
          title: '网络错误',
        })
      },
      complete: (res) => {
        wx.hideLoading();
      }
    })
  },
  // 我的房屋登陆判断
  handleMyHouseTap() {
    if (isLogin()) {
      wx.navigateTo({
        url: '/house_pkg/pages/list/index',
      })
    } else {
      wx.navigateTo({
        url: '/pages/login/index?from=/house_pkg/pages/list/index',
      })
    }
  },
  // 在线报修登陆判断
  handleRepairTap() {
    if (isLogin()) {
      wx.navigateTo({
        url: `/repair_pkg/pages/form/index`,
      })
    } else {
      wx.navigateTo({
        url: `/pages/login/index?from=/repair_pkg/pages/form/index`,
      })
    }
  }
})